<template>
	<view class="user_register_register_page">
		<view class="page_content full_page  bg-ff">
			<view class="form_block">
				<view class="margin-left-30 padding-right-30 flex align-center line-height-100 border-bottom-ed">
					<text class="text-28 text-1a">手机号</text>
					<input class="margin-left-40 flex-one" type="number" name="mobile_phone" maxlength="11" v-model="mobile_phone"
					 placeholder="请输入手机号" placeholder-class="text-28 text-aa" />
				</view>

				<view class="padding-lr-30 flex align-center line-height-100 border-bottom-ed">
					<text class="text-28 text-1a">验证码</text>
					<input class="margin-lr-40 flex-one" type="number" name="code" maxlength="4" v-model="code" placeholder="请输入验证码"
					 placeholder-class="text-28 text-aa" />
					<ty-register-get-code :mobile-phone="mobile_phone"></ty-register-get-code>
				</view>

				<view class="margin-top-100 margin-lr-30 line-height-90 radius-45 bg-main-gradient text-center text-32 text-ff" @click="register">
					注册
				</view>
				
				<view class="margin-top-40 line-height-40 text-center text-28 text-98" @click="skip">
					跳过绑定
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				third_type: '', //三方授权进入的注册页 类型
				third_id: '', //三方授权进入的注册页 授权ID
				mobile_phone: '',
				code: ''
			}
		},

		onLoad(options) {
			this.third_type = options.hasOwnProperty('type') ? options.type : ''
			this.third_id = options.hasOwnProperty('id') ? options.id : ''
		},

		methods: {
			// 注册并登录
			register() {
				if (!this.mobile_phone) {
					this.cn.toast("请输入手机号")
					return false
				}
				if (!this.code) {
					this.cn.toast("请输入验证码")
					return false
				}

				this.rq.getData('base/user/api/Login/login', {
					mobile_phone: this.mobile_phone,
					code: this.code,
					type: 1,
					third_type: this.third_type,
					third_id: this.third_id
				}).then(res => {
					if (res.code === 0) {
						uni.setStorageSync('user_id', res.data.user_id)
						uni.setStorageSync('access_token', res.data.access_token)
						uni.setStorageSync('access_token_expire_time', res.data.access_token_expire_time)
						
						uni.navigateBack({
							delta: 1
						})
					}
				})
			},
			
			skip() {
				uni.navigateBack({
					delta: 1
				})
				// this.$emit('skip')
			}
		}
	}
</script>

<style scoped>

</style>
